#include "widget.h"
#include "ui_widget.h"
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <QHBoxLayout>
#include <QPropertyAnimation>
#include <QGraphicsDropShadowEffect>
#include "realtimecandlestickchart.h"
#include <QGuiApplication>
#include <QScreen>
#include <QStandardItem>
#include <QTimer>



Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //无边框窗口设计
    setWindowFlags(Qt::FramelessWindowHint);
    setWindowOpacity(0.95);
    setFixedSize(1900,1000);
    //resize(1900,1000);
     //setWindowState(windowState() | Qt::WindowMaximized);
    // setStyleSheet("QWidget#contentWidget { "
    //               "background-color: rgba(255, 255, 255, 200); "  // 半透明白色背景
    //               "border-radius: 15px; "                         // 圆角边框
    //               "}");


/**
    RealTimeCandlestickChart*chart=new RealTimeCandlestickChart;
    ui->horizontalLayout->addWidget(chart);
*/


    //设置时间定时刷新
    QTimer*timer=new QTimer(this);
    timer->start(1000);//1s显示一次
    connect(timer,&QTimer::timeout,this,&Widget::slotTimerUpdate);

    //设置stackwidget默认页为首页
    ui->stackedWidget->setCurrentIndex(0);



    m_model=new QStandardItemModel(this);
    m_model->setHorizontalHeaderLabels(QStringList() <<"时间" << "类型" << "价格"<<"数量"<<"总额"<<"利润"<<"余额");

    m_model->setItem(0,0,new QStandardItem("2025/11/09 19:32"));
    m_model->setItem(0,1,new QStandardItem("BTC/USDT"));
    m_model->setItem(0,2,new QStandardItem("1020000"));
    m_model->setItem(0,3,new QStandardItem("1"));
    m_model->setItem(0,4,new QStandardItem("10000"));
    m_model->setItem(0,5,new QStandardItem("110000"));
    m_model->setItem(0,6,new QStandardItem("30$"));

    ui->tableView_trade->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableView_trade->setModel(m_model);


}

Widget::~Widget()
{
    delete ui;
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        m_dragging = true;
        m_dragPosition = event->globalPosition().toPoint() - frameGeometry().topLeft();
        event->accept();
    }
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    if (m_dragging && (event->buttons() & Qt::LeftButton)) {
        move(event->globalPosition().toPoint() - m_dragPosition);
        event->accept();
    }
}

void Widget::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        m_dragging = false;
        event->accept();
    }
}

void Widget::slotTimerUpdate()
{
    QDateTime time=QDateTime::currentDateTime();//获取当前时间
    QString str_time=time.toString("yyyy/MM/dd hh:mm:ss");
    ui->label_time->setText(str_time);
}





void Widget::on_pushButton_real_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);

}


void Widget::on_pushButton_backtrader_clicked()
{
     ui->stackedWidget->setCurrentIndex(1);


}


void Widget::on_pushButton_hide_clicked()
{
    showMinimized();
}


void Widget::on_pushButton_max_clicked()
{
    showMaximized();
}


void Widget::on_pushButton_close_clicked()
{
    this->close();
}

